//index.js
//获取应用实例
const app = getApp()
Page({
  data: {
    date: '',
    start_date: '',
    end_date: '',
    begin: '北京',
    end: '上海',
    items: [
      { name: 'student', value: '学生票' },
      //checked为truetrue，所以该项默认选中
      { name: 'speed', value: '高铁动车' },
    ]

  },

  onLoad: function (options) {
    var that = this
    wx.request({
      url: "https://wx.dong.sowtai.com/test/time.php",

      success: function (res) {
        console.log(res)
        if (res.statusCode == 200) {
          var time = res.data.today
          var times = time.split("-")
          var dates = times[1] + "月" + times[2] + "日"
          that.setData({
            date: dates,
            start_date: res.data.today,
            end_date: res.data.later_time
          })
        }
      }
    })
  },


  onReady: function () {

  },
  //日期选择器
  bindDateChange(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    var time = e.detail.value
    var times = time.split("-")
    var dates = times[1] + "月" + times[2] + "日"
    this.setData({
      date: dates
    })
  },
  //城市选择器
  bindMultiPickerChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      multiIndex: e.detail.value
    })
  },
  bindBeginCityView: function () {
    wx.navigateTo({
      url: '../city/city?cityType=begin',
    })
  },
  bindEndCityView: function () {
    wx.navigateTo({
      url: '../city/city?cityType=end',
    })
  },
  onShow: function () {
    this.setData({ begin: app.globalData.trainBeginCity })
    this.setData({ end: app.globalData.trainEndCity })
  }
})

